﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraAdjust : MonoBehaviour 
{
    private SpriteRenderer gameBg;
    private Sprite[] sprite_gameBg = new Sprite[4];

    private void Start()
    {
        gameBg = transform.Find("GameBg").GetComponent<SpriteRenderer>();
        for (int i = 0; i < sprite_gameBg.Length; i++)
        {
            sprite_gameBg[i] = ResManager.Instance.LoadSourceSprite("Textures2D/bg" + (i + 1));        
        }
        RandomSprite_gameBg();
        //游戏背景大小适配
        Vector3 posAdjust = Camera.main.ScreenToWorldPoint(Vector3.zero);
        gameBg.size = new Vector2(
            Mathf.Abs(Camera.main.transform.position.x - posAdjust.x) * 2,
            Mathf.Abs(Camera.main.transform.position.y - posAdjust.y) * 2
            );
    }



    /// <summary>
    /// 随机游戏背景图
    /// </summary>
    private void RandomSprite_gameBg()
    {
        int ra = Random.Range(0, 4);
        gameBg.sprite = sprite_gameBg[ra];
    }

}
